<template>
  <div class="subapplicant-content">
    <el-collapse v-model="activeNames">
      <el-collapse-item name="1" class="transform-down">
        <template #title>
          <span class="circle"></span>
          <span class="collapse-title"
            >文件编号：{{
              modeltype == "circulation"
                ? requestForm.nonContractSealCode
                : modeltype == "contract"
                ? requestForm.contractCode
                : modeltype == "sealcontract"
                ? requestForm.purchaseContractCode
                : modeltype == "serveContract"
                ? requestForm.intellectualPropertyCode
                : ""
            }}</span
          >
        </template>
        <div class="textcontent">
          <div class="item">
            <div class="item-title">申请类型:</div>
            <div class="item-text">
              合同用印{{
                modeltype == "circulation"
                  ? requestForm.nonContractTypeName
                  : modeltype == "contract"
                  ? requestForm.contractKindName
                  : modeltype == "sealcontract"
                  ? requestForm.contractTypeName
                  : modeltype == "serveContract"
                  ? requestForm.contractTypeName
                  : ""
              }}
            </div>
          </div>
          <div class="item">
            <div class="item-title">申请时间:</div>
            <div class="item-text">
              {{
                modeltype == "circulation"
                  ? requestForm.applyTime
                  : modeltype == "contract"
                  ? requestForm.createTime
                  : modeltype == "sealcontract"
                  ? requestForm.applicantDate
                  : modeltype == "serveContract"
                  ? requestForm.applicantDate
                  : ""
              }}
            </div>
          </div>
          <div class="item">
            <div class="item-title">申请部门:</div>
            <div class="item-text">{{ requestForm.deptName }}</div>
          </div>
          <div class="item">
            <div class="item-title">
              {{ modeltype == "circulation" ? "文件类型:" : "合同类型:" }}
            </div>
            <div class="item-text">
              {{
                modeltype == "circulation"
                  ? requestForm.fileTypeNameName
                  : modeltype == "contract"
                  ? requestForm.contractKindName
                  : modeltype == "sealcontract"
                  ? requestForm.contractTypeName
                  : modeltype == "serveContract"
                  ? requestForm.contractTypeName
                  : ""
              }}
            </div>
          </div>
          <div class="item">
            <div class="item-title">应归档份数:</div>
            <div class="item-text">
              {{ requestForm.pigeonholeNumber || "--" }}
            </div>
          </div>
        </div>
      </el-collapse-item>
      <Archivedetails
        @close="close"
        @submitAuditing="submitAuditing"
        :detaildataArray="requestForm.archiveFileList"
        :pigeonholeNumber="requestForm.pigeonholeNumber"
        :pagestatus="pagestatus"
      ></Archivedetails>
    </el-collapse>
  </div>
</template>

<script setup>
import Archivedetails from "./archivedetails.vue";
import { nonConSealCheck } from "@/api/seal/circulation";
import { checkContractApi } from "@/api/sales/contract";
import { checkSealApi } from "@/api/purchase/contractSeal";
import { checkSealApi as contractSealApi } from "@/api/serve/contractSeal";
import { ref, onMounted, provide, inject } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";

const emits = defineEmits(["closeauditDialog1", "handleBack"]);

const props = defineProps({
  // 合同数据
  requestForm: {
    type: Object,
    default: {},
  },
  pagestatus: {
    type: String,
    default: "",
  },
  modeltype: {
    type: String,
    default: "circulation",
  },
});
console.log("requestForm", props.requestForm);
const getNonContractual = inject("getNonContractual");

/**
 * @description: 提交审核
 */
const submitAuditing = (archiveFileList) => {
  let tatol = archiveFileList.reduce(
    (total, item) => total + item.realCount * 1,
    0
  );
  let params = {
    auditRemark: "合同归档",
    checkStatus: 3,
    archiveFileList,
    flowIntype: props.requestForm.nextAudit.flowIntype,
    shouldCountAll: props.requestForm.pigeonholeNumber,
    realCountAll: tatol,
  };
  let Func;
  switch (props.modeltype) {
    case "circulation":
      Func = nonConSealCheck;
      params.nonContractSealId = props.requestForm.nonContractSealId;
      break;
    case "contract":
      Func = checkContractApi;
      params.contractId = props.requestForm.contractId;
      params.contractKind = props.requestForm.contractKind;
      break;
    case "sealcontract":
      Func = checkSealApi;
      params.contractCheckStatus = 3;
      params.purchaseContractId = props.requestForm.purchaseContractId;
      params.purchaseOrderId = props.requestForm.purchaseOrderId;
      params.purchaseInqMaterialDetailLitsRespVos =
        props.requestForm.purchaseInqMaterialDetailLitsRespVos;
      break;
    case "serveContract":
      Func = contractSealApi;
      params.contractCheckStatus = 3;
      params.purchaseContractId = props.requestForm.purchaseContractId;
      params.contractType = props.requestForm.contractType;
      break;
    default:
      break;
  }
  Func(params).then((res) => {
    if (res.code == 200) {
      ElMessage.success("操作成功");
      emits("closeauditDialog1");
      emits("handleBack");
      getNonContractual();
    }
  });
};

const close = () => {
  emits("closeauditDialog1");
};

/**
 * @description: 回显详情
 */
const handlerdetail = () => {};
defineExpose({
  handlerdetail,
});

// 折叠栏默认展开
const activeNames = ref(["1", "2", "3"]);
</script>

<style scoped lang="scss">
.subapplicant-content {
  height: 450px;
  .textcontent {
    padding: 0px 20px;
    margin: 10px 0;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    background-color: #f0f0f0;
    .item {
      display: flex;
      width: 33%;
      height: 50px;
      line-height: 50px;
      .item-title {
        font-size: 14px;
        font-weight: 700;
        margin-right: 10px;
      }
    }
  }
}
.subapplicant-content {
  overflow-y: scroll;
}
</style>
